[R-package] limit exported symbols in DLL #4494
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Through investigation of #4464, I've learned a lot about how R loads DLLs for packages. Particularly, I've learned that there are some settings where two DLLs having the same symbols can lead to conflicts that cause crashes or incorrect behavior.
This PR proposes a change to limit the visibility of symbols in the
lightgbm.dll
created for this project's R package.From https://cran.r-project.org/doc/manuals/R-exts.html#Writing-portable-packages
From https://cran.r-project.org/doc/manuals/R-exts.html#Controlling-visibility
And from https://cran.r-project.org/doc/manuals/R-exts.html#Creating-shared-objects.
How this improves
{lightgbm}
This does not fix #4464, but it might help to avoid future similar issues where LightGBM's DLL has exported symbols that conflict with the exports from other DLLs loaded in users' sessions.
How to test this
I used
dumpbin.exe
to examine the exported symbols from the package DLL before and after this change.In my case, I used the
dumpbin.exe
bundled with Visual Studio. Like this:Before this change, the CRAN package's DLL had 3983 exported symbols.
`dumpbin` results (click me)
After this change, the CRAN package's DLL had exactly 1 exported symbol.
`dumpbin` results (click me)
This change does not impact the DLL produced by CMake-based builds. Before and after this change, CMake package's DLL had 151 exported symbols.
`dumpbin` results (click me)